package org.manager.authorize;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;

public class Function implements Serializable {

	private static final long serialVersionUID = 6170853861905301772L;
	
	private String id="";
	
	private String roleId;
	private String menuId;
	
	private String add = "false";
	private String del = "false";
	private String modify = "false";
	private String imp = "false";
	private String exp = "false";
	
	
	public Function() {
	}

	@Override
	public int hashCode() {
		int result = 7;
		result = 31*result+id.hashCode();
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(!(obj instanceof Function)){
			return false;
		}
		
		if(((Function)obj).getId() == null){
			return false;
		}
		
		if(((Function)obj).getId().equals(id)){
			return true;
		}
		return false;
	}
	
	
	public String isAddChecked(){
		return getCheckedString(this.add);
	}
	
	public String isDelChecked(){
		return getCheckedString(this.del);
	}
	
	public String isModifyChecked(){
		return getCheckedString(this.modify);
	}
	
	public String isImpChecked(){
		return getCheckedString(this.imp);
	}
	
	public String isExpChecked(){
		return getCheckedString(this.exp);
	}
	
	/**
	 * 是否有功能被选中.
	 * @return
	 */
	public boolean hasFunctonChecked(){
		if(isAddChecked().equalsIgnoreCase("checked") || isDelChecked().equalsIgnoreCase("checked") || isModifyChecked().equalsIgnoreCase("checked")
				|| isImpChecked().equalsIgnoreCase("checked") || isExpChecked().equalsIgnoreCase("checked")){
			return true;
		}
		return false;
	}
	
	private String getCheckedString(String fun){
		if(StringUtils.isNotBlank(fun)){
			if(!fun.equalsIgnoreCase("false") && !fun.equalsIgnoreCase("0")){
				return "checked";
			}
		}
		return "";
	}
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getAdd() {
		return add;
	}

	public void setAdd(String add) {
		this.add = add;
	}

	public String getDel() {
		return del;
	}

	public void setDel(String del) {
		this.del = del;
	}

	public String getModify() {
		return modify;
	}

	public void setModify(String modify) {
		this.modify = modify;
	}

	public String getImp() {
		return imp;
	}

	public void setImp(String imp) {
		this.imp = imp;
	}

	public String getExp() {
		return exp;
	}

	public void setExp(String exp) {
		this.exp = exp;
	}

	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	public String getMenuId() {
		return menuId;
	}

	public void setMenuId(String menuId) {
		this.menuId = menuId;
	}

	
}
